from django.shortcuts import render
import pymysql
from django.http import JsonResponse,FileResponse
from django.shortcuts import HttpResponse, render
import json
import numpy
import copy
import random
from .Judge import Judge
from .Skill import Skill

class Damage:
    def __init__(self,res):
        self.res = res
        self.zengbu = 1
        self.zengbu_reduce = 0
        self.shanguafugai = 0
        self.bing_buff = []
        self.biangua_celue = {
            "山卦":{
                "变卦":False,
                "概率":0.5,
            },
            "水卦":{
                "变卦":True,
                "概率":0.5,
            },
            "火卦":{
                "变卦":True,
                "概率":0.5,
            }
        }
        if self.res["shan_ifbian"] == True:
            self.biangua_celue["山卦"]["变卦"] = False
            self.biangua_celue["山卦"]["概率"] = 0.5
        else:
            self.biangua_celue["山卦"]["变卦"] = True
            self.biangua_celue["山卦"]["概率"] = round(int(self.res["shan_bian_huo"])*0.01,2)
        if self.res["shui_ifbian"] == True:
            self.biangua_celue["水卦"]["变卦"] = False
            self.biangua_celue["水卦"]["概率"] = 0.5
        else:
            self.biangua_celue["水卦"]["变卦"] = True
            self.biangua_celue["水卦"]["概率"] = round(int(self.res["shui_bian_shan"])*0.01,2)
        if self.res["huo_ifbian"] == True:
            self.biangua_celue["火卦"]["变卦"] = False
            self.biangua_celue["火卦"]["概率"] = 0.5
        else:
            self.biangua_celue["火卦"]["变卦"] = True
            self.biangua_celue["火卦"]["概率"] = round(int(self.res["huo_bian_shan"])*0.01,2)



        self.skill_sim_log = []
        self.skill_log = []
        self.current_buff = []
        self.deng_gcd = 0
        self.bian_gcd = 0
        self.feijian_level = 0
        self.xingyun = 100

        self.current = {
            "name":[""],
            "time":0,
        }
        self.target = {
            "火离":{
                "存在":False,
                "跳数":0,
                "GCD":Skill(self.res).huo[6],
                "cold_down":Skill(self.res).huo[6],
            },
            "杀星在尾1":{
                "存在":False,
                "跳数":0,
                "GCD":1,
                "cold_down":1+0.75,
            },
            "杀星在尾2":{
                "存在":False,
                "跳数":0,
                "GCD":1,
                "cold_down":1+0.75,
            },
            "兵主逆":{
                "存在":False,
                "跳数":0,
                "GCD":Skill(self.res).bing[6],
                "cold_down":Skill(self.res).bing[6],
            },

        }
        self.qi_delay = [-1]
        self.skills = {
                        "奇门飞宫":{
                            "CD":15,
                            "充能":2,
                            "剩余充能":2,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "灵器":{
                            "CD":0,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "天斗旋":{
                            "CD":4+Skill(self.res).dou[6],
                            "充能":1,
                            "剩余充能":1,
                            "消耗":-20,
                            "cold_down":0,
                        },
                        "兵主逆":{
                            "CD":5,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":-15,
                            "cold_down":0,
                        },
                        "三星临":{
                            "CD":0,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":-5,
                            "cold_down":0,
                        },
                        "往者定":{
                            "CD":20,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "杀星在尾":{
                            "CD":20.75,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "返闭惊魂":{
                            "CD":31.375,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "鬼星开穴":{
                            "CD":10,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":60,
                            "cold_down":0,
                        },
                        "起卦":{
                            "CD":20,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "变卦":{
                            "CD":20,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":45,
                            "cold_down":0,
                        },
                        "祝由·火离":{
                            "CD":0,
                            "充能":0,
                            "剩余充能":0,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "归一":{
                            "CD":30,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "飞剑":{
                            "CD":6,
                            "充能":1,
                            "剩余充能":1,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "飞剑·意":{
                            "CD":0,
                            "充能":0,
                            "剩余充能":0,
                            "消耗":0,
                            "cold_down":0,
                        },
                        "手附魔": {
                            "CD": 16.75,
                            "充能": 1,
                            "剩余充能": 1,
                            "消耗": 0,
                            "cold_down": 0,
                        },
                        "巨门北落": {
                            "CD": 35,
                            "充能": 1,
                            "剩余充能": 1,
                            "消耗": 0,
                            "cold_down": 0,
                        },
        }
        #手大附魔
        if self.res["models_check"] != ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
            self.skills["手附魔"]["CD"] = 10
        # 善友
        if "善友" in self.res["buff"]:
            self.res["models_check"] = ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]
            self.skills["奇门飞宫"]["CD"] = 12.6
            self.skills["天斗旋"]["CD"] = 3.6+Skill(self.res).dou[6]
            self.skills["兵主逆"]["CD"] = 4.5
            self.skills["杀星在尾"]["CD"] = 40.5
            self.skills["返闭惊魂"]["CD"] = 19.8
            self.skills["鬼星开穴"]["CD"] = 9
            self.skills["起卦"]["CD"] = 18
            self.skills["变卦"]["CD"] = 18

        self.xingyun_max = 100
        # 奇穴亘天天斗旋充能
        if self.res["qixue_7"] == "3":
            self.skills["天斗旋"]["充能"] =3
            self.skills["天斗旋"]["剩余充能"] =3
        # 斗大附魔
        if self.res["shangku"] == "3":
            self.skills['天斗旋']['CD'] = 8 + Skill(self.res).dou[6]
        # 奇穴征凶
        if self.res["qixue_10"] == "1":
            self.biangua_celue["山卦"]["变卦"] = True
            self.biangua_celue["山卦"]["概率"] = 1
            self.biangua_celue["火卦"]["变卦"] = True
            self.biangua_celue["火卦"]["概率"] = 1
            self.biangua_celue["水卦"]["变卦"] = True
            self.biangua_celue["水卦"]["概率"] = 0


        self.buffs = {
                        "魂灯1":{
                            "存在":False,
                            "time":0,
                        },
                        "魂灯2":{
                            "存在":False,
                            "time":0,
                        },
                        "魂灯3":{
                            "存在":False,
                            "time":0,
                        },
                        "魂阵":{
                            "存在":False,
                            "time":0,
                        },
                        "鬼遁":{
                            "存在":False,
                            "time":0,
                        },
                        "荧入白":{
                            "存在":False,
                            "time":0,
                        },
                        "山艮":{
                            "存在":False,
                            "time":0,
                        },
                        "水坎":{
                            "存在":False,
                            "time":0,
                        },
                        "火离":{
                            "存在":False,
                            "time":0,
                        },
                        "祝祷":{
                            "存在":False,
                            "time":0,
                        },
                        "归一":{
                            "存在":False,
                            "time":0,
                        },
                        "飞剑·意":{
                            "存在":False,
                            "time":0,
                        },
                        "春节阵·朱雀":{
                            "存在":False,
                            "time":0,
                        },
                        "巨门北落": {
                            "存在": False,
                            "time": 0,
                        },

        }
        if "提前放灯" in self.res["buff"] and self.res["qixue_12"] == "1":
            self.buffs["魂灯1"]["存在"] = True
            self.buffs["魂灯1"]["time"] = 35
            self.buffs["魂灯2"]["存在"] = True
            self.buffs["魂灯2"]["time"] = 36
            self.buffs["魂灯3"]["存在"] = True
            self.buffs["魂灯3"]["time"] = 37
            self.skills["奇门飞宫"]["剩余充能"] = 0
            self.skills["奇门飞宫"]["cold_down"] = 5

        if "起手鬼遁" in self.res["buff"]:
            self.buffs["鬼遁"]["存在"] = True
            self.buffs["鬼遁"]["time"] = 30
        if "春节阵·朱雀" in self.res["buff"]:
            self.buffs["春节阵·朱雀"]["存在"] = True
            self.buffs["春节阵·朱雀"]["time"] = 20

    # 星运消耗计算
    # def cal_xingyun(self,skill):
    #     cal = self.skills[skill]["消耗"]
    #     self.xingyun -= cal
    #     if self.xingyun < 0:
    #         return False
    #     elif self.xingyun > 100:
    #         self.xingyun = 100
    #         return True
    #     else:
    #         return True
    # 技能释放日志
    def log(self,skill_name,damage,buff,time_stamp):
        self.skill_log.append(
                {
                    "name":skill_name,
                    "damage":int(damage[0]),
                    "buff":buff,
                    "time_stamp":time_stamp,
                }
        )
    def sim_log(self,skill_name,skill_type,time_stamp):
        self.skill_sim_log.append(
                {
                    "name":skill_name,
                    "type":skill_type,
                    "time_stamp":time_stamp,
                }
        )
    # 每帧开始的时候刷新BUFF
    def time_start(self,t):
        if self.xingyun > self.xingyun_max:
            self.xingyun = self.xingyun_max
        if self.target["火离"]["存在"] is False and self.zengbu_reduce != 0 and self.zengbu >1:
            self.zengbu_reduce -= 0.0625
            if self.zengbu_reduce == 0:
                self.zengbu_reduce = 2
                # self.zengbu -= 0.1
                self.zengbu -= 0.06
        # 橙武特效
        if self.buffs["归一"]["存在"] == True:
            self.skills["兵主逆"]["cold_down"] = 0
            self.skills["兵主逆"]["剩余充能"] = 1
            self.skills["天斗旋"]["cold_down"] = 0
            self.skills["天斗旋"]["剩余充能"] = 1

        # 判定是否有加强魂阵在场，方便判断触发灵器
        if self.buffs["魂灯1"]["存在"] :
            if self.buffs["魂灯2"]["存在"] :
                if self.buffs["魂灯3"]["存在"] :
                    self.buffs["魂阵"]["存在"] = True
                    # self.buffs["魂阵"]["time"] = min(self.buffs["魂灯1"]["time"],self.buffs["魂灯2"]["time"],self.buffs["魂灯3"]["time"])
        # 判定是否触发荧入白
        if self.buffs["山艮"]["存在"]:
            if self.res["qixue_4"] == "1":
                self.buffs["荧入白"]["存在"] = True
        if self.buffs["水坎"]["存在"] :
            if self.res["qixue_4"] == "1":
                self.buffs["荧入白"]["存在"] = True
        if self.buffs["火离"]["存在"] :
            if self.res["qixue_4"] == "1":
                self.buffs["荧入白"]["存在"] = True
        # 判定是否触发祝祷
        if self.xingyun > 40:
            if self.res["qixue_7"] == "1":
                self.buffs["祝祷"]["存在"] = True
        # 将所有触发的buff添加进即时buff列表
        for key in self.buffs.keys():
            if self.buffs[key]["存在"] :
                self.current_buff.append(key)
        # 起卦延迟2s触发生效
        if self.qi_delay[0] == 0 :
            # 稳定模式
            if self.res["models_check"] == ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
                # gua = "火离"
                gua = "山艮"
                if self.res["qixue_12"] == "1" or self.res["qixue_12"] == "6":
                    gua = "山艮"
                    # gua = "火离"
            elif self.res["models_check"] == ["黑鬼限定"]:
                gua = "水坎"
            else:
                gua_list = ["火离","山艮","水坎"]
                gua = random.choice(gua_list)

            if gua == "火离":
                self.skills["祝由·火离"]["剩余充能"] = 1
            self.buffs[gua]["存在"] = True
            self.buffs[gua]["time"] = 19
            if gua == "火离":
                self.buffs["山艮"]["存在"] = False
                self.buffs["山艮"]["time"] = 0
                self.buffs["水坎"]["存在"] = False
                self.buffs["水坎"]["time"] = 0
            if gua == "山艮":
                self.buffs["火离"]["存在"] = False
                self.buffs["火离"]["time"] = 0
                self.buffs["水坎"]["存在"] = False
                self.buffs["水坎"]["time"] = 0
            if gua == "水坎":
                self.buffs["山艮"]["存在"] = False
                self.buffs["山艮"]["time"] = 0
                self.buffs["火离"]["存在"] = False
                self.buffs["火离"]["time"] = 0

            self.qi_delay[0] -= 0.0625
            self.log(gua,[0,],[],t)
            self.sim_log(gua,"卦象生成",t)
        else:
            self.qi_delay[0] -= 0.0625
    # 结算dot
    def dot_pass(self,t):
        buff_list = []
        buff = copy.copy(self.current_buff)
        if "荧入白" in buff and self.res["qixue_4"] == "1":
            buff_list.append("荧入白")
        if "祝祷" in buff and self.res["qixue_7"] == "1":
            buff_list.append("祝祷")
        if "鬼遁" in buff and self.res["qixue_6"] == "1":
            buff_list.append("鬼遁")
        for key,value in self.target.items():
            if self.target[key]["存在"] and self.target[key]["跳数"]>0:
                self.target[key]["cold_down"] -= 0.0625
                if self.target[key]["cold_down"] == 0:
                    if key == "火离":
                        damage = Judge(self.res, Skill(self.res).huo, buff_list).d()
                        if self.res["qixue_12"] == "1" or self.res["qixue_12"] == "6":
                            dam = (int(damage[0]*self.zengbu),damage[1],damage[2])
                        else:
                            dam = damage
                        self.log("火离",dam,buff_list,t)
                        # print(t,"火离",self.target["火离"],self.zengbu)
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        # 触发飞剑
                        self.feijian_yi(t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        if self.target[key]["跳数"] == 0 :
                            self.target[key]["存在"] = False
                            self.sim_log("祝由·火离","火离消失",t)
                            self.zengbu_reduce = 2
                    elif key == "杀星在尾1":
                        damage = Judge(self.res,Skill(self.res).sha,buff_list).d()
                        self.log("杀星在尾",damage,buff_list,t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        # 触发飞剑
                        self.feijian_yi(t)
                        if self.target[key]["跳数"] == 0 :
                            self.target[key]["存在"] = False
                            self.sim_log("杀星在尾","杀星消失",t)
                    elif key == "杀星在尾2":
                        damage = Judge(self.res,Skill(self.res).sha,buff_list).d()
                        self.log("杀星在尾",damage,buff_list,t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        # 触发飞剑
                        self.feijian_yi(t)
                        if self.target[key]["跳数"] == 0 :
                            self.target[key]["存在"] = False
                    elif key == "兵主逆":
                        if '山艮' in buff:
                            buff.remove('山艮')
                        if self.bing_buff == ['山艮']:
                            buff.append('山艮')
                            # print(buff)
                        damage = Judge(self.res,Skill(self.res).bing,buff).d()
                        self.log("兵主逆",damage,buff,t)
                        self.zengb()
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        # 触发飞剑
                        self.feijian_yi(t)
                        # 触发灵器
                        if "魂阵" in self.current_buff:
                            buff_1 = []
                            if "鬼遁" in buff:
                                buff_1.append("鬼遁")
                            if "祝祷" in buff:
                                buff_1.append("祝祷")
                            if "荧入白" in buff:
                                buff_1.append("荧入白")
                            damage_1 = Judge(self.res,Skill(self.res).ling,buff_1).d()
                            self.log("灵器",damage_1,buff_1,t)
                            self.xingyun -= self.skills["灵器"]["消耗"]
                        if self.target[key]["跳数"] == 0 :
                            self.target[key]["存在"] = False
                            self.bing_buff = []
    # 时间结算
    def time_pass(self,t):
        if "山艮" in self.current_buff:
            self.shanguafugai += 0.0625
        self.dot_pass(t)
        self.current_buff = [] # 清空即时buff列表
        # 转GCD
        self.current["time"] -= 0.0625
        if self.current["time"] == 0:
            self.current["name"] = [""]
        # 技能计时
        for key,value in self.skills.items():
            if self.skills[key]["充能"] > self.skills[key]["剩余充能"]:
                self.skills[key]["cold_down"] -= 0.0625
                if self.skills[key]["cold_down"] <= 0:
                    self.skills[key]["剩余充能"] += 1
                    if self.skills[key]["充能"] > self.skills[key]["剩余充能"]:
                        self.skills[key]["cold_down"] = self.skills[key]["CD"]
                    if key == '杀星在尾':
                        self.target["杀星在尾1"]["cold_down"] = 1+0.75
                        self.target["杀星在尾2"]["cold_down"] = 1+0.75
        # buff计时
        for key,value in self.buffs.items():
            if self.buffs[key]["存在"] is True:
                self.buffs[key]["time"] -= 0.0625
                if self.buffs[key]["time"] <= 0 :
                    self.buffs[key]["存在"] = False
        # 放灯GCD
        if self.deng_gcd > 0 :
            self.deng_gcd -= 1
        # 变卦GCD
        if self.bian_gcd > 0 :
            self.bian_gcd -= 1
        # # 起卦延迟2s触发生效
        # if self.qi_delay[0] == 0 :
        #     gua_list = ["火离","山艮","水坎"]
        #     gua = random.choice(gua_list)
        #     if gua == "火离":
        #         self.skills["祝由·火离"]["剩余充能"] = 1
        #     self.buffs[gua]["存在"] = True
        #     self.buffs[gua]["time"] = 19
        #     self.qi_delay[0] -= 0.0625
        #     self.log(gua,[0,],[],t)
        # else:
        #     self.qi_delay[0] -= 0.0625
    # 飞剑攒层数
    def feijian_zan(self,t):
        if "飞剑·意" in self.res["buff"]:
            if self.skills["飞剑"]["剩余充能"] == 1:
                self.skills["飞剑"]["剩余充能"] = 0
                self.skills["飞剑"]["cold_down"] = self.skills["飞剑"]["CD"]
                self.feijian_level += 1
                if self.feijian_level == 5:
                    self.skills["飞剑·意"]["剩余充能"] = 1
                elif self.feijian_level > 5:
                    self.feijian_level = 5
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res,Skill(self.res).feijian,buff).d()
                self.log("剑风",damage,buff,t)
                self.sim_log("剑风","武器被动",t)
    # 使用飞剑武器
    def feijian_yi(self,t):
        if "飞剑·意" in self.res["buff"]:
            self.feijian_zan(t)
            if self.skills["飞剑·意"]["剩余充能"] == 1:
                self.skills["飞剑·意"]["剩余充能"] = 0
                self.feijian_level = 0
                self.current_buff.append("飞剑·意")
                self.buffs["飞剑·意"]["存在"] = True
                self.buffs["飞剑·意"]["time"] = 6
                buff = copy.copy(self.current_buff)
                damage = [0,]
                self.log("飞剑·意",damage,buff,t)
                self.sim_log("飞剑·意","武器特效",t)
    # 返闭惊魂
    def fanbijinghun(self,t):
        if self.skills["返闭惊魂"]["剩余充能"] >0 and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆":
            if self.buffs["魂灯1"]["存在"] is False:
                self.buffs["魂灯1"]["存在"] = True
                self.buffs["魂灯1"]["time"] = 40
                self.skills["返闭惊魂"]["剩余充能"] -= 1
                if self.skills["返闭惊魂"]["充能"] - self.skills["返闭惊魂"]["剩余充能"] == 1:
                    self.skills["返闭惊魂"]["cold_down"] = self.skills["返闭惊魂"]["CD"]
                buff = copy.copy(self.current_buff)
                damage = [0,]
                self.log("返闭惊魂",damage,buff,t)
                self.sim_log("返闭惊魂","技能施放",t)
            else:
                if self.buffs["魂灯2"]["存在"] is False:
                    self.buffs["魂灯2"]["存在"] = True
                    self.buffs["魂灯2"]["time"] = 40
                    self.skills["返闭惊魂"]["剩余充能"] -= 1
                    if self.skills["返闭惊魂"]["充能"] - self.skills["返闭惊魂"]["剩余充能"] == 1:
                        self.skills["返闭惊魂"]["cold_down"] = self.skills["返闭惊魂"]["CD"]
                    buff = copy.copy(self.current_buff)
                    damage = [0,]
                    self.log("返闭惊魂",damage,buff,t)
                    self.sim_log("返闭惊魂","技能施放",t)
                else:
                    if self.buffs["魂灯3"]["存在"] is False:
                        self.buffs["魂灯3"]["存在"] = True
                        self.buffs["魂灯3"]["time"] = 40
                        self.skills["返闭惊魂"]["剩余充能"] -= 1
                        if self.skills["返闭惊魂"]["充能"] - self.skills["返闭惊魂"]["剩余充能"] == 1:
                            self.skills["返闭惊魂"]["cold_down"] = self.skills["返闭惊魂"]["CD"]
                        buff = copy.copy(self.current_buff)
                        damage = [0,]
                        self.log("返闭惊魂",damage,buff,t)
                        self.sim_log("返闭惊魂","技能施放",t)
    # 奇门飞宫
    def qimenfeigong(self,t):
        if self.skills["奇门飞宫"]["剩余充能"] >0 and self.deng_gcd == 0 and self.buffs["魂阵"]["存在"] == False and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆":
            if self.buffs["魂灯1"]["存在"] is False:
                self.buffs["魂灯1"]["存在"] = True
                self.buffs["魂灯1"]["time"] = 40
                self.skills["奇门飞宫"]["剩余充能"] -= 1
                if self.skills["奇门飞宫"]["充能"] - self.skills["奇门飞宫"]["剩余充能"] == 1:
                    self.skills["奇门飞宫"]["cold_down"] = self.skills["奇门飞宫"]["CD"]
                self.deng_gcd = 16
                buff = copy.copy(self.current_buff)
                damage = [0,]
                self.log("奇门飞宫",damage,buff,t)
                self.sim_log("奇门飞宫","技能施放",t)
            else:
                if self.buffs["魂灯2"]["存在"] is False:
                    self.buffs["魂灯2"]["存在"] = True
                    self.buffs["魂灯2"]["time"] = 40
                    self.skills["奇门飞宫"]["剩余充能"] -= 1
                    if self.skills["奇门飞宫"]["充能"] - self.skills["奇门飞宫"]["剩余充能"] == 1:
                        self.skills["奇门飞宫"]["cold_down"] = self.skills["奇门飞宫"]["CD"]
                    self.deng_gcd = 16
                    buff = copy.copy(self.current_buff)
                    damage = [0,]
                    self.log("奇门飞宫",damage,buff,t)
                    self.sim_log("奇门飞宫","技能施放",t)
                else:
                    if self.buffs["魂灯3"]["存在"] is False:
                        self.buffs["魂灯3"]["存在"] = True
                        self.buffs["魂灯3"]["time"] = 40
                        self.skills["奇门飞宫"]["剩余充能"] -= 1
                        if self.skills["奇门飞宫"]["充能"] - self.skills["奇门飞宫"]["剩余充能"] == 1:
                            self.skills["奇门飞宫"]["cold_down"] = self.skills["奇门飞宫"]["CD"]
                        self.deng_gcd = 16
                        self.current_buff.append("魂阵")
                        buff = copy.copy(self.current_buff)
                        damage = [0,]
                        self.log("奇门飞宫",damage,buff,t)
                        self.sim_log("奇门飞宫","技能施放",t)
    #鬼星开穴
    def guixingkaixue(self,t):
        if self.skills["鬼星开穴"]["剩余充能"] >0 and self.buffs["魂灯3"]["存在"] == True and self.deng_gcd == 0 and self.xingyun>=self.skills["鬼星开穴"]["消耗"] and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆":
            self.buffs["鬼遁"]["存在"] = True
            self.buffs["鬼遁"]["time"] = 30
            self.buffs["魂灯1"]["存在"] = False
            self.buffs["魂灯1"]["time"] = 0
            self.buffs["魂灯2"]["存在"] = False
            self.buffs["魂灯2"]["time"] = 0
            self.buffs["魂灯3"]["存在"] = False
            self.buffs["魂灯3"]["time"] = 0
            self.buffs["魂阵"]["存在"] = False
            self.buffs["魂阵"]["time"] = 0
            self.current_buff.remove("魂灯1")
            self.current_buff.remove("魂灯2")
            self.current_buff.remove("魂灯3")
            self.current_buff.remove("魂阵")
            if "鬼遁" not in self.current_buff:
                self.current_buff.append("鬼遁")
            self.skills["鬼星开穴"]["剩余充能"] -= 1
            # 如果炸火卦，目标带火离DOT
            if self.buffs["火离"]["存在"]:
                if self.target["火离"]["存在"]:
                    self.target["火离"]["跳数"] = 9
                    self.sim_log("祝由·火离","刷新火离跳数",t)
                else:
                    self.target["火离"]["存在"] = True
                    self.target["火离"]["cold_down"] = Skill(self.res).huo[6] #这边模拟的不准确,忘记刷新DOT时间的机制了
                    self.target["火离"]["跳数"] = 9
            # 用完后进CD
            if self.skills["鬼星开穴"]["充能"] - self.skills["鬼星开穴"]["剩余充能"] == 1:
                self.skills["鬼星开穴"]["cold_down"] = self.skills["鬼星开穴"]["CD"]
            self.deng_gcd = 16
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res,Skill(self.res).kai,buff).d()
            # 触发橙武
            # self.cw(t)
            # 触发手大附魔
            self.shou(t)
            # 触发飞剑
            self.feijian_yi(t)
            self.log("鬼星开穴",damage,buff,t)
            self.sim_log("鬼星开穴","技能施放",t)
            self.xingyun -= self.skills["鬼星开穴"]["消耗"]
    # 起卦
    def qigua(self,t):
        if self.skills["起卦"]["剩余充能"] >0 and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆":
            self.qi_delay = [2.5]
            self.skills["起卦"]["剩余充能"] -= 1
            self.skills["起卦"]["cold_down"] = self.skills["起卦"]["CD"]
            buff = copy.copy(self.current_buff)
            damage = [0,]
            self.log("起卦",damage,buff,t)
            self.sim_log("起卦","起卦",t)
            self.xingyun -= self.skills["起卦"]["消耗"]
    # 增卜
    def zengb(self):
        if self.res["qixue_12"] == "1" or self.res["qixue_12"] == "6" and self.target["火离"]["存在"] :
            # self.zengbu += 0.2
            # if self.zengbu > 2:
            #     self.zengbu = 2
            self.zengbu += 0.12
            if self.zengbu > 1.6:
                self.zengbu = 1.6
    # 祝由·火离
    def huoli(self,t):
        if self.skills["祝由·火离"]["剩余充能"] == 1 and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆":
            self.skills["祝由·火离"]["剩余充能"] = 0
            if self.target["火离"]["存在"]:
                self.target["火离"]["跳数"] = 9 #这边模拟的不准确,忘记刷新DOT时间的机制了
            else:
                self.target["火离"]["存在"] = True
                self.target["火离"]["cold_down"] = Skill(self.res).huo[6]
                self.target["火离"]["跳数"] = 9
            buff = copy.copy(self.current_buff)
            damage = [0,]
            self.log("火离施放",damage,buff,t)
            self.sim_log("祝由·火离","技能施放",t)
            self.xingyun -= self.skills["祝由·火离"]["消耗"]
    # 变卦
    def biangua(self,t):
        if self.skills["变卦"]["剩余充能"] >0 and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆" and self.xingyun>=self.skills["变卦"]["消耗"]:
            if "山艮" in self.current_buff and self.biangua_celue["山卦"]["变卦"]:
                self.skills["变卦"]["剩余充能"] -= 1
                self.skills["变卦"]["cold_down"] = self.skills["变卦"]["CD"]
                self.xingyun -= self.skills["变卦"]["消耗"]
                k = random.random()
                m = self.biangua_celue["山卦"]["概率"]  # 山变火的概率
                if k < m:
                    # 变火卦
                    self.skills["祝由·火离"]["剩余充能"] = 1
                    self.buffs["火离"]["存在"] = True
                    self.buffs["火离"]["time"] = 19
                    self.current_buff.remove("山艮")
                    self.current_buff.append("火离")
                    self.buffs["山艮"]["存在"] = False
                    self.buffs["山艮"]["time"] = 0
                    self.log("变卦·山变火",[0,],[],t)
                    self.sim_log("变卦·山变火","技能施放",t)
                    self.bian_gcd = 14
                else:
                    # 变水卦
                    self.buffs["水坎"]["存在"] = True
                    self.buffs["水坎"]["time"] = 19
                    self.current_buff.remove("山艮")
                    self.current_buff.append("水坎")
                    self.buffs["山艮"]["存在"] = False
                    self.buffs["山艮"]["time"] = 0
                    self.log("变卦·山变水",[0,],[],t)
                    self.sim_log("变卦·山变水","技能施放",t)
                    self.bian_gcd = 14
                return
            if "水坎" in self.current_buff and self.biangua_celue["水卦"]["变卦"]:
                self.skills["变卦"]["剩余充能"] -= 1
                self.skills["变卦"]["cold_down"] = self.skills["变卦"]["CD"]
                self.xingyun -= self.skills["变卦"]["消耗"]
                k = random.random()
                # if self.res["models_check"] == ["黑鬼模式（0星运起手只出水）"]:
                #     m = 1
                # else:
                #     m = self.biangua_celue["水卦"]["概率"]  # 水变山的概率
                m = self.biangua_celue["水卦"]["概率"]  # 水变山的概率
                if k < m:
                    # 变山卦
                    self.buffs["山艮"]["存在"] = True
                    self.buffs["山艮"]["time"] = 19
                    self.current_buff.remove("水坎")
                    self.current_buff.append("山艮")
                    self.buffs["水坎"]["存在"] = False
                    self.buffs["水坎"]["time"] = 0
                    self.log("变卦·水变山",[0,],[],t)
                    self.sim_log("变卦·水变山","技能施放",t)
                    self.bian_gcd = 14
                else:
                    # 变火卦
                    self.skills["祝由·火离"]["剩余充能"] = 1
                    self.buffs["火离"]["存在"] = True
                    self.buffs["火离"]["time"] = 19
                    self.current_buff.remove("水坎")
                    self.current_buff.append("火离")
                    self.buffs["水坎"]["存在"] = False
                    self.buffs["水坎"]["time"] = 0
                    self.log("变卦·水变火",[0,],[],t)
                    self.sim_log("变卦·水变火","技能施放",t)
                    self.bian_gcd = 14
                return

            if "火离" in self.current_buff and self.biangua_celue["火卦"]["变卦"]:
                self.skills["变卦"]["剩余充能"] -= 1
                self.skills["变卦"]["cold_down"] = self.skills["变卦"]["CD"]
                self.xingyun -= self.skills["变卦"]["消耗"]
                k = random.random()
                if self.res["models_check"] == ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
                    m = 1
                else:
                    m = self.biangua_celue["火卦"]["概率"]  # 火变山的概率
                if k < m:
                    # 变山卦
                    self.buffs["山艮"]["存在"] = True
                    self.buffs["山艮"]["time"] = 19
                    self.current_buff.remove("火离")
                    self.current_buff.append("山艮")
                    self.buffs["火离"]["存在"] = False
                    self.buffs["火离"]["time"] = 0
                    self.log("变卦·火变山",[0,],[],t)
                    self.sim_log("变卦·火变山","技能施放",t)
                    self.bian_gcd = 14
                else:
                    # 变水卦
                    self.buffs["水坎"]["存在"] = True
                    self.buffs["水坎"]["time"] = 19
                    self.current_buff.remove("火离")
                    self.current_buff.append("水坎")
                    self.buffs["火离"]["存在"] = False
                    self.buffs["火离"]["time"] = 0
                    self.log("变卦·火变水",[0,],[],t)
                    self.sim_log("变卦·火变水","技能施放",t)
                    self.bian_gcd = 14
                return
    # 往者定
    def wang(self,t):
        if self.current["time"] == 0 and self.skills["往者定"]["剩余充能"] >= 1:
            self.skills["往者定"]["剩余充能"] -= 1
            self.skills["往者定"]["cold_down"] = self.skills["往者定"]["CD"]
            self.current["name"] = ["往者定"]
            self.current["time"] = Skill(self.res).ding[6]
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res,Skill(self.res).ding,buff).d()
            # 触发橙武
            # self.cw(t)
            # 触发手大附魔
            self.shou(t)
            # 触发飞剑
            self.feijian_yi(t)
            self.log("往者定",damage,buff,t)
            self.sim_log("往者定","技能施放",t)
            self.xingyun -= self.skills["往者定"]["消耗"]
            # 触发灵器 #往者定还是不触发灵器
            # if "魂阵" in self.current_buff:
            #     buff_1 = []
            #     if "鬼遁" in buff:
            #         buff_1.append("鬼遁")
            #     if "祝祷" in buff:
            #         buff_1.append("祝祷")
            #     if "荧入白" in buff:
            #         buff_1.append("荧入白")
            #     damage_1 = Judge(self.res,Skill(self.res).ling,buff_1).d()
            #     self.log("灵器",damage_1,buff_1,t)
            #     self.xingyun -= self.skills["灵器"]["消耗"]
    # 兵主逆
    def bing(self,t):
        if self.current["time"] == 0 and self.skills["兵主逆"]["剩余充能"] == 1:
            self.skills["兵主逆"]["剩余充能"] -= 1
            self.skills["兵主逆"]["cold_down"] = self.skills["兵主逆"]["CD"]
            self.current["name"] = ["兵主逆"]

            if self.res["ping"] == 2:
                ping_k = 1
            else:
                ping_k = self.res["ping"]
            # self.current["time"] = Skill(self.res).bing[6]*3+(self.res["ping"]-1)*0.0625
            self.current["time"] = Skill(self.res).bing[6] * 3+(ping_k-1)*0.0625

            self.target["兵主逆"]["存在"] = True
            self.target["兵主逆"]["跳数"] = 3
            buff = copy.copy(self.current_buff)
            if "山艮" in self.current_buff:
                self.bing_buff = ['山艮']
            # damage = Judge(self.res,Skill(self.res).bing,buff).d()
            damage = [0,]
            self.log("兵主逆施放",damage,buff,t)
            self.sim_log("兵主逆","技能施放",t)
            self.xingyun -= self.skills["兵主逆"]["消耗"]
    # 天斗旋
    def dou(self,t):
        if self.current["time"] == 0 and self.skills["天斗旋"]["剩余充能"] >= 1:
            if self.skills["天斗旋"]["剩余充能"] == self.skills["天斗旋"]["充能"]:
                self.skills["天斗旋"]["cold_down"] = self.skills["天斗旋"]["CD"]
            self.skills["天斗旋"]["剩余充能"] -= 1

            self.current["name"] = ["天斗旋"]
            self.current["time"] = Skill(self.res).dou[6]
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res,Skill(self.res).dou,buff).d()
            self.log("天斗旋",damage,buff,t)
            self.sim_log("天斗旋","技能施放",t)
            # self.zengb() #不触发增卜
            # 触发橙武
            # self.cw(t)
            # 触发手大附魔
            self.shou(t)
            # 触发飞剑
            self.feijian_yi(t)
            self.xingyun -= self.skills["天斗旋"]["消耗"]
            # 触发灵器
            if "魂阵" in self.current_buff:
                buff_1 = []
                if "鬼遁" in buff:
                    buff_1.append("鬼遁")
                if "祝祷" in buff:
                    buff_1.append("祝祷")
                if "荧入白" in buff:
                    buff_1.append("荧入白")
                damage_1 = Judge(self.res,Skill(self.res).ling,buff_1).d()
                self.log("灵器",damage_1,buff_1,t)
                self.xingyun -= self.skills["灵器"]["消耗"]
    # 三星临
    def lin(self,t):
        if self.current["time"] == 0 and self.skills["三星临"]["剩余充能"] >= 1:
            self.skills["三星临"]["cold_down"] = self.skills["三星临"]["CD"]
            self.current["name"] = ["三星临"]
            self.current["time"] = Skill(self.res).lin[6]
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res,Skill(self.res).lin,buff).d()
            self.log("三星临",damage,buff,t)
            self.sim_log("三星临","技能施放",t)
            # self.zengb() # 不触发增卜
            self.xingyun -= self.skills["三星临"]["消耗"]
            # 触发橙武
            # self.cw(t)
            # 触发手大附魔
            self.shou(t)
            # 触发飞剑
            self.feijian_yi(t)
            # 触发灵器
            if "魂阵" in self.current_buff:
                buff_1 = []
                if "鬼遁" in buff:
                    buff_1.append("鬼遁")
                if "祝祷" in buff:
                    buff_1.append("祝祷")
                if "荧入白" in buff:
                    buff_1.append("荧入白")
                damage_1 = Judge(self.res,Skill(self.res).ling,buff_1).d()
                self.log("灵器",damage_1,buff_1,t)
                self.xingyun -= self.skills["灵器"]["消耗"]
    # 杀星在尾
    def sha(self,t):
        if self.current["time"] == 0 and self.skills["杀星在尾"]["剩余充能"] >= 1:
            self.skills["杀星在尾"]["剩余充能"] -= 1
            self.skills["杀星在尾"]["cold_down"] = self.skills["杀星在尾"]["CD"]
            self.current["name"] = ["杀星在尾"]
            self.current["time"] = Skill(self.res).sha[6]
            self.target["杀星在尾1"]["存在"] = True
            self.target["杀星在尾1"]["跳数"] = 5
            self.target["杀星在尾2"]["存在"] = True
            self.target["杀星在尾2"]["跳数"] = 5
            buff = copy.copy(self.current_buff)
            # damage = Judge(self.res,Skill(self.res).bing,buff).d()
            damage = [0,]
            self.log("杀星在尾施放",damage,buff,t)
            self.sim_log("杀星在尾","技能施放",t)
            self.xingyun -= self.skills["杀星在尾"]["消耗"]
    def cw(self,t):
        if "POWER·归一" in self.res["buff"]:
            if self.skills["归一"]["剩余充能"] == 1:
                m = random.random()
                if self.res["models_check"] == ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
                    m = 0
                if m <= 0.10:
                    self.skills["归一"]["cold_down"] = self.skills["归一"]["CD"]
                    self.skills["归一"]["剩余充能"] = 0
                    self.skills["兵主逆"]["cold_down"] = 0
                    self.skills["兵主逆"]["剩余充能"] = 1
                    self.skills["天斗旋"]["cold_down"] = 0
                    self.skills["天斗旋"]["剩余充能"] = 1
                    self.buffs["归一"]["存在"] = True
                    self.buffs["归一"]["time"] = 6
                    buff = copy.copy(self.current_buff)
                    damage = [0,]
                    self.log("橙武触发",damage,buff,t)
                    self.sim_log("橙武触发","技能施放",t)
    def shou(self,t):
        if "伤手大附魔" in self.res["buff"]:
            if self.skills["手附魔"]["剩余充能"] == 1:
                m = random.random()
                if self.res["models_check"] == ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
                    m = 0
                if m <= 0.10:
                    self.skills["手附魔"]["剩余充能"] -= 1
                    self.skills["手附魔"]["cold_down"] = self.skills["手附魔"]["CD"]
                    buff = copy.copy(self.current_buff)
                    damage = Judge(self.res, Skill(self.res).shou, buff).d()
                    self.log("手附魔", damage, buff, t)
                    self.sim_log("手附魔", "附魔触发", t)
                    # self.zengb() #不触发增卜
                    # 触发橙武
                    # self.cw(t)
                    # 触发飞剑
                    self.feijian_yi(t)
                    # self.xingyun -= self.skills["手附魔"]["消耗"]

    # 巨门北落
    def jumen(self, t):
        if self.res['shangku'] == '2':
            if self.skills["巨门北落"]["剩余充能"] > 0 and self.current["name"][0] != "天斗旋" and self.current["name"][0] != "兵主逆":
                self.skills["巨门北落"]["剩余充能"] -= 1
                self.skills["巨门北落"]["cold_down"] = self.skills["巨门北落"]["CD"]
                self.buffs["巨门北落"]["存在"] = True
                self.buffs["巨门北落"]["time"] = 8
                buff = copy.copy(self.current_buff)
                damage = [0, ]
                self.log("巨门北落", damage, buff, t)
                self.sim_log("巨门北落", "爆发", t)

    # 开始模拟
    def start(self):
        # 录入正式循环
        if self.res["zengyifugai"]["fenzhong"] is True:
            total_time = 300
        elif self.res["zengyifugai"]["fenzhong"] is False:
            total_time = 180
        # 杀星循环
        if self.res["qixue_12"] == "4":
            for t in numpy.arange(0,total_time,0.0625):

                try:
                    # print(t,self.buffs)
                    self.time_start(t)
                    if t == 0:
                        self.sha(t)
                    if t <= 4:
                        self.qigua(t)
                        # 善友无脑变
                        if "善友" in self.res["buff"]:
                            if self.buffs["火离"]["存在"]:
                                self.huoli(t)
                                self.biangua(t)
                        if self.buffs["火离"]["存在"] is False:
                            self.biangua(t)
                            self.huoli(t)
                        else:
                            self.huoli(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.fanbijinghun(t)
                            self.qimenfeigong(t)
                        if self.target["火离"]["存在"]:
                            self.bing(t)
                            self.lin(t)
                        # self.wang(t)
                        self.dou(t)
                        self.lin(t)
                    else:
                        # 起卦
                        if "善友" in self.res["buff"]:
                            kt = 3
                        else:
                            kt = 3
                        if self.buffs["山艮"]["存在"] is False and self.buffs["水坎"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                            self.qigua(t)
                        if self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["火离"]["存在"] and self.buffs["火离"]["time"] < kt and self.skills["返闭惊魂"]["cold_down"]>2:
                            self.qigua(t)
                        if self.target["火离"]["存在"] and (self.target["火离"]["跳数"]*2+ self.target["火离"]["cold_down"])< 4  :
                            self.qigua(t)
                        if "善友" not in self.res["buff"]:
                            if self.target["火离"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                self.biangua(t)
                                self.huoli(t)
                        # 变卦
                        # 善友无脑变
                        if "善友" in self.res["buff"]:
                                if self.buffs["火离"]["存在"]:
                                    if self.skills["起卦"]["cold_down"] <= 18:
                                        self.huoli(t)
                                        self.biangua(t)
                        else:
                            # if (self.target["火离"]["cold_down"]+2*(self.target["火离"]["跳数"])) <3:
                            #     if self.buffs["火离"]["存在"] is False:
                            #         self.biangua(t)
                            if self.buffs["火离"]["存在"]:
                                if self.skills["起卦"]["cold_down"] <= 20:
                                    self.huoli(t)
                                    self.biangua(t)
                        #炸灯
                        # if self.skills["返闭惊魂"]["剩余充能"] == 1 or self.skills["返闭惊魂"]["cold_down"] < self.current["time"]+Skill(self.res).dou[6]:
                        if self.skills["返闭惊魂"]["剩余充能"] == 1 :
                            if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                self.lin(t)
                                self.guixingkaixue(t)
                                if self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 0:
                                    self.qigua(t)
                                elif self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 1:
                                    self.huoli(t)
                                    self.qigua(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.qimenfeigong(t)
                            self.fanbijinghun(t)
                        # 主动火离
                        if self.target["火离"]["存在"] is False or (self.target["火离"]["cold_down"]+self.target["火离"]["GCD"]*(self.target["火离"]["跳数"]-1))<3:
                            self.huoli(t)
                        # if self.buffs["归一"]["存在"] and "魂阵" in self.current_buff:
                        #     if self.buffs["鬼遁"]["存在"] is False and t>30:
                        #         self.lin(t)
                        #         self.guixingkaixue(t)
                        #     else:
                        #         self.bing(t)

                        self.bing(t)
                        self.sha(t)
                        self.dou(t)


                        self.lin(t)
                    self.time_pass(t)
                except Exception as e:
                    print(self.skill_sim_log)
                    print(e)
        # 新增卜循环
        elif self.res["qixue_12"] == "1":
            for t in numpy.arange(0,total_time,0.0625):
                # print(t,self.skills["天斗旋"])
                try:
                    # print(t,self.buffs)
                    self.time_start(t)
                    if "提前放灯" in self.res["buff"]:
                        if t == 0:
                            self.lin(t)
                        if t <= 17:
                            self.qigua(t)
                            if self.buffs["火离"]["存在"] is False and self.target["火离"]["存在"] is False:
                                self.biangua(t)
                                self.huoli(t)
                            else:
                                self.huoli(t)
                            if self.target["火离"]["存在"]:
                                if self.res['shangku'] == '2':
                                    self.jumen(t)
                                self.bing(t)
                            self.dou(t)
                            self.lin(t)
                        else:
                            if self.res['shangku'] == '2':
                                self.jumen(t)
                            # 起卦
                            if "善友" in self.res["buff"]:
                                kt = 3
                            else:
                                kt = 3
                            if self.buffs["山艮"]["存在"] is False and self.buffs["水坎"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                self.qigua(t)
                            if self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] < 1.7 :
                                self.qigua(t)
                            if self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] < kt :
                                self.qigua(t)
                            if self.buffs["火离"]["存在"] and self.buffs["火离"]["time"] < kt and self.skills["返闭惊魂"]["cold_down"]>2:
                                self.qigua(t)
                            if self.target["火离"]["存在"] and (self.target["火离"]["跳数"]*2+ self.target["火离"]["cold_down"])< 4  :
                                self.qigua(t)
                            if "善友" not in self.res["buff"]:
                                if self.target["火离"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                    self.biangua(t)
                                    self.huoli(t)
                            # 变卦
                            # 善友无脑变
                            if "善友" in self.res["buff"]:
                                    if self.buffs["火离"]["存在"]:
                                        if self.skills["起卦"]["cold_down"] <= 20:
                                            self.huoli(t)
                                            self.biangua(t)
                            else:
                                if (self.target["火离"]["cold_down"]+2*(self.target["火离"]["跳数"])) <3:
                                    if self.buffs["火离"]["存在"] is False:
                                        self.biangua(t)
                            # 火变山
                            if self.buffs["火离"]["存在"] is True and self.target["火离"]["跳数"] >3 and self.skills["返闭惊魂"]["cold_down"]<24 and self.skills["返闭惊魂"]["cold_down"]>20 :
                                self.huoli(t)
                                self.biangua(t)

                            #炸灯
                            if "善友" in self.res["buff"]:
                                if self.skills["奇门飞宫"]["剩余充能"]*14+(12.6-self.skills["奇门飞宫"]["cold_down"]) >=25.5:
                                    # print(t,self.skills["奇门飞宫"]["剩余充能"]*12.6+(12.6-self.skills["奇门飞宫"]["cold_down"]),self.skills["兵主逆"]["cold_down"])
                                    if self.skills["兵主逆"]["cold_down"] >= 1.3:
                                        self.lin(t)
                                        self.guixingkaixue(t)
                            else:
                                # if self.skills["奇门飞宫"]["剩余充能"]*14+(14-self.skills["奇门飞宫"]["cold_down"]) >=25.5:
                                if self.skills["返闭惊魂"]["剩余充能"] == 1 or self.skills["返闭惊魂"]["cold_down"] < Skill(self.res).dou[6]*2:
                                # if self.skills["返闭惊魂"]["剩余充能"] == 1 :
                                    if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                        self.lin(t)
                                        self.guixingkaixue(t)
                                        if self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 0:
                                            self.qigua(t)
                                        elif self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 1:
                                            self.huoli(t)
                                            self.qigua(t)

                            # 放灯
                            if "魂阵" not in self.current_buff:
                                self.qimenfeigong(t)
                                self.fanbijinghun(t)
                            # 主动火离
                            if self.target["火离"]["存在"] is False or (self.target["火离"]["cold_down"]+self.target["火离"]["GCD"]*(self.target["火离"]["跳数"]-1))<3:
                                self.huoli(t)
                            self.bing(t)
                            self.dou(t)
                            self.lin(t)
                    else:
                        if t == 0:
                            self.lin(t)
                        if t <= 4:
                            self.qigua(t)
                            # 善友无脑变
                            if "善友" in self.res["buff"]:
                                if self.buffs["火离"]["存在"]:
                                    self.huoli(t)
                                    self.biangua(t)
                            if self.buffs["火离"]["存在"] is False:
                                self.biangua(t)
                                self.huoli(t)
                            else:
                                self.huoli(t)
                            # 放灯
                            if "魂阵" not in self.current_buff:
                                self.fanbijinghun(t)
                                self.qimenfeigong(t)
                            if self.target["火离"]["存在"]:
                                self.bing(t)
                                self.lin(t)
                            # self.wang(t)
                            self.dou(t)
                            self.lin(t)
                        else:
                            # 起卦
                            if "善友" in self.res["buff"]:
                                kt = 3
                            else:
                                kt = 3
                            if self.buffs["山艮"]["存在"] is False and self.buffs["水坎"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                self.qigua(t)
                            if self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] < kt :
                                self.qigua(t)
                            if self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] < kt :
                                self.qigua(t)
                            if self.buffs["火离"]["存在"] and self.buffs["火离"]["time"] < kt and self.skills["返闭惊魂"]["cold_down"]>2:
                                self.qigua(t)
                            if self.target["火离"]["存在"] and (self.target["火离"]["跳数"]*2+ self.target["火离"]["cold_down"])< 4  :
                                self.qigua(t)
                            if "善友" not in self.res["buff"]:
                                if self.target["火离"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                    self.biangua(t)
                                    self.huoli(t)
                            # 变卦
                            # 善友无脑变
                            if "善友" in self.res["buff"]:
                                    if self.buffs["火离"]["存在"]:
                                        if self.skills["起卦"]["cold_down"] <= 20:
                                            self.huoli(t)
                                            self.biangua(t)
                            else:
                                if (self.target["火离"]["cold_down"]+2*(self.target["火离"]["跳数"])) <3:
                                    if self.buffs["火离"]["存在"] is False:
                                        self.biangua(t)
                            #炸灯
                            if "善友" in self.res["buff"]:
                                if self.skills["奇门飞宫"]["剩余充能"]*14+(12.6-self.skills["奇门飞宫"]["cold_down"]) >=25.5:
                                    # print(t,self.skills["奇门飞宫"]["剩余充能"]*12.6+(12.6-self.skills["奇门飞宫"]["cold_down"]),self.skills["兵主逆"]["cold_down"])
                                    if self.skills["兵主逆"]["cold_down"] >= 1.3:
                                        self.lin(t)
                                        self.guixingkaixue(t)
                            else:
                                # if self.skills["奇门飞宫"]["剩余充能"]*14+(14-self.skills["奇门飞宫"]["cold_down"]) >=25.5:
                                if self.skills["返闭惊魂"]["剩余充能"] == 1 or self.skills["返闭惊魂"]["cold_down"] < self.current["time"]+Skill(self.res).dou[6]:
                                # if self.skills["返闭惊魂"]["剩余充能"] == 1 :
                                    if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                        self.lin(t)
                                        self.guixingkaixue(t)
                                        if self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 0:
                                            self.qigua(t)
                                        elif self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 1:
                                            self.huoli(t)
                                            self.qigua(t)
                            # 放灯
                            if "魂阵" not in self.current_buff:
                                self.qimenfeigong(t)
                                self.fanbijinghun(t)
                            # 主动火离
                            if self.target["火离"]["存在"] is False or (self.target["火离"]["cold_down"]+self.target["火离"]["GCD"]*(self.target["火离"]["跳数"]-1))<3:
                                self.huoli(t)
                            # if self.buffs["归一"]["存在"] and "魂阵" in self.current_buff:
                            #     if self.buffs["鬼遁"]["存在"] is False and t>30:
                            #         self.lin(t)
                            #         self.guixingkaixue(t)
                            #     else:
                            #         self.bing(t)
                            self.bing(t)
                            self.dou(t)
                            self.lin(t)
                    self.time_pass(t)
                except Exception as e:
                    print(self.skill_sim_log)
                    print(e)
        elif self.res["qixue_12"] == "6":
            for t in numpy.arange(0,total_time,0.0625):
                try:
                    # print(t,self.buffs)
                    self.time_start(t)
                    if t == 0:
                        self.lin(t)
                    if t <= 4:
                        self.qigua(t)
                        if self.buffs["火离"]["存在"] is False:
                            self.biangua(t)
                            self.huoli(t)
                        else:
                            self.huoli(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.fanbijinghun(t)
                            self.qimenfeigong(t)
                        if self.target["火离"]["存在"]:
                            self.bing(t)
                            self.lin(t)
                        # self.wang(t)
                        self.dou(t)
                        self.lin(t)
                    else:
                        #变卦
                        if (self.target["火离"]["cold_down"]+self.target["火离"]["GCD"]*(self.target["火离"]["跳数"]-1)) <2:
                            if self.buffs["火离"]["存在"] is False:
                                if  self.skills["返闭惊魂"]["cold_down"] < 15 and self.skills["返闭惊魂"]["剩余充能"] != 1:
                                    self.biangua(t)
                                    self.huoli(t)
                                elif self.skills["返闭惊魂"]["cold_down"] >19:
                                    self.biangua(t)
                                    self.huoli(t)
                                elif self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] <3:
                                    self.biangua(t)
                                    self.huoli(t)
                                elif self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] <3:
                                    self.biangua(t)
                                    self.huoli(t)
                        #有火卦并且CD足够提前炸
                        if  self.skills["返闭惊魂"]["cold_down"] < 2* Skill(self.res).dou[6] and self.skills["返闭惊魂"]["剩余充能"] != 1:
                            if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                if self.buffs["火离"]["存在"] is False:
                                    self.biangua(t)
                                self.lin(t)
                                self.guixingkaixue(t)
                        # 规矩的炸灯
                        if self.skills["返闭惊魂"]["剩余充能"] == 1:
                            if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                # if t == 66.6875:
                                #     print(self.buffs["火离"])
                                if self.buffs["火离"]["存在"] is False:
                                    self.biangua(t)
                                self.lin(t)
                                self.guixingkaixue(t)
                        # 起卦
                        if "善友" in self.res["buff"]:
                            kt = 3
                        else:
                            kt = 3
                        # if  self.skills["返闭惊魂"]["cold_down"] >= 2  or  self.skills["返闭惊魂"]["剩余充能"] != 1:
                        if self.buffs["山艮"]["存在"] is False and self.buffs["水坎"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                            self.qigua(t)
                        if self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["火离"]["存在"] and self.buffs["火离"]["time"] < kt :
                            self.qigua(t)
                        if self.target["火离"]["存在"] and ((self.target["火离"]["跳数"]-1)*2+ self.target["火离"]["cold_down"])< 3  :
                            self.qigua(t)
                        if "善友" not in self.res["buff"]:
                            if self.target["火离"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                self.biangua(t)
                                self.huoli(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.fanbijinghun(t)
                            self.qimenfeigong(t)
                        if "魂阵" in self.current_buff:
                            self.bing(t)
                        self.dou(t)
                        self.lin(t)
                    self.time_pass(t)
                except Exception as e:
                    print(self.skill_sim_log)
                    print(e)
        # 杀星循环
        if self.res["qixue_12"] == "7":
            for t in numpy.arange(0,total_time,0.0625):
                try:
                    # print(t,self.buffs)
                    self.time_start(t)
                    if t == 0:
                        self.sha(t)
                    if t <= 4:
                        self.qigua(t)
                        # 善友无脑变
                        if "善友" in self.res["buff"]:
                            if self.buffs["火离"]["存在"]:
                                self.huoli(t)
                                self.biangua(t)
                        if self.buffs["火离"]["存在"] is False:
                            self.biangua(t)
                            self.huoli(t)
                        else:
                            self.huoli(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.fanbijinghun(t)
                            self.qimenfeigong(t)
                        if self.target["火离"]["存在"]:
                            self.bing(t)
                            self.lin(t)
                        # self.wang(t)
                        self.dou(t)
                        self.lin(t)
                    else:
                        # 起卦
                        if "善友" in self.res["buff"]:
                            kt = 3
                        else:
                            kt = 3
                        if self.buffs["山艮"]["存在"] is False and self.buffs["水坎"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                            self.qigua(t)
                        if self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["火离"]["存在"] and self.buffs["火离"]["time"] < kt and self.skills["返闭惊魂"]["cold_down"]>2:
                            self.qigua(t)
                        if self.target["火离"]["存在"] and (self.target["火离"]["跳数"]*2+ self.target["火离"]["cold_down"])< 4  :
                            self.qigua(t)
                        if "善友" not in self.res["buff"]:
                            if self.target["火离"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                self.biangua(t)
                                self.huoli(t)
                        # 变卦
                        # 善友无脑变
                        if "善友" in self.res["buff"]:
                                if self.buffs["火离"]["存在"]:
                                    if self.skills["起卦"]["cold_down"] <= 18:
                                        self.huoli(t)
                                        self.biangua(t)
                        else:
                            # if (self.target["火离"]["cold_down"]+2*(self.target["火离"]["跳数"])) <3:
                            #     if self.buffs["火离"]["存在"] is False:
                            #         self.biangua(t)
                            if self.buffs["火离"]["存在"]:
                                if self.skills["起卦"]["cold_down"] <= 20:
                                    self.huoli(t)
                                    self.biangua(t)
                        #炸灯
                        # if self.skills["返闭惊魂"]["剩余充能"] == 1 or self.skills["返闭惊魂"]["cold_down"] < self.current["time"]+Skill(self.res).dou[6]:
                        if self.skills["返闭惊魂"]["剩余充能"] == 1 :
                            if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                self.lin(t)
                                self.guixingkaixue(t)
                                if self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 0:
                                    self.qigua(t)
                                elif self.buffs["火离"]["存在"] and self.skills["祝由·火离"]["剩余充能"] == 1:
                                    self.huoli(t)
                                    self.qigua(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.qimenfeigong(t)
                            self.fanbijinghun(t)
                        # 主动火离
                        if self.target["火离"]["存在"] is False or (self.target["火离"]["cold_down"]+self.target["火离"]["GCD"]*(self.target["火离"]["跳数"]-1))<3:
                            self.huoli(t)
                        # if self.buffs["归一"]["存在"] and "魂阵" in self.current_buff:
                        #     if self.buffs["鬼遁"]["存在"] is False and t>30:
                        #         self.lin(t)
                        #         self.guixingkaixue(t)
                        #     else:
                        #         self.bing(t)
                        self.sha(t)
                        self.dou(t)
                        self.bing(t)
                        self.lin(t)
                    self.time_pass(t)
                except Exception as e:
                    print(self.skill_sim_log)
                    print(e)
        # 杀星循环
        if self.res["qixue_12"] == "8":
            for t in numpy.arange(0,total_time,0.0625):
                try:
                    # print(t,self.buffs)
                    self.time_start(t)
                    if t == 0:
                        self.sha(t)
                    if t <= 4:
                        self.qigua(t)
                        # 善友无脑变
                        if "善友" in self.res["buff"]:
                            if self.buffs["火离"]["存在"]:
                                self.huoli(t)
                                self.biangua(t)
                        if self.buffs["火离"]["存在"] is False:
                            self.biangua(t)
                            self.huoli(t)
                        else:
                            self.huoli(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.fanbijinghun(t)
                            self.qimenfeigong(t)
                        if self.target["火离"]["存在"]:
                            self.bing(t)
                            self.lin(t)
                        # self.wang(t)
                        self.dou(t)
                        self.lin(t)
                    else:
                        # 起卦
                        if "善友" in self.res["buff"]:
                            kt = 3
                        else:
                            kt = 3
                        if self.buffs["山艮"]["存在"] is False and self.buffs["水坎"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                            self.qigua(t)
                        if self.buffs["山艮"]["存在"] and self.buffs["山艮"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["水坎"]["存在"] and self.buffs["水坎"]["time"] < kt :
                            self.qigua(t)
                        if self.buffs["火离"]["存在"] and self.buffs["火离"]["time"] < kt and self.skills["返闭惊魂"]["cold_down"]>2:
                            self.qigua(t)
                        if self.target["火离"]["存在"] and (self.target["火离"]["跳数"]*2+ self.target["火离"]["cold_down"])< 4  :
                            self.qigua(t)
                        if "善友" not in self.res["buff"]:
                            if self.target["火离"]["存在"] is False and self.buffs["火离"]["存在"] is False:
                                self.biangua(t)
                                self.huoli(t)
                        # 变卦
                        # 善友无脑变
                        if "善友" in self.res["buff"]:
                                if self.buffs["火离"]["存在"]:
                                    if self.skills["起卦"]["cold_down"] <= 18:
                                        self.huoli(t)
                                        self.biangua(t)
                        else:
                            # if (self.target["火离"]["cold_down"]+2*(self.target["火离"]["跳数"])) <3:
                            #     if self.buffs["火离"]["存在"] is False:
                            #         self.biangua(t)
                            if self.buffs["火离"]["存在"]:
                                if self.skills["起卦"]["cold_down"] <= 20:
                                    self.huoli(t)
                                    self.biangua(t)
                        #有火卦并且CD足够提前炸
                        if  self.skills["返闭惊魂"]["cold_down"] < 2* Skill(self.res).dou[6] and self.skills["返闭惊魂"]["剩余充能"] != 1:
                            if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                if self.buffs["火离"]["存在"] is False:
                                    self.biangua(t)
                                self.lin(t)
                                self.guixingkaixue(t)
                                self.qigua(t)
                        # 规矩的炸灯
                        if self.skills["返闭惊魂"]["剩余充能"] == 1:
                            if self.skills["兵主逆"]["cold_down"] >= 1.6:
                                # if t == 66.6875:
                                #     print(self.buffs["火离"])
                                if self.buffs["火离"]["存在"] is False:
                                    self.biangua(t)
                                self.lin(t)
                                self.guixingkaixue(t)
                                self.qigua(t)
                        # 放灯
                        if "魂阵" not in self.current_buff:
                            self.qimenfeigong(t)
                            self.fanbijinghun(t)
                        # 主动火离
                        if self.target["火离"]["存在"] is False or (self.target["火离"]["cold_down"]+self.target["火离"]["GCD"]*(self.target["火离"]["跳数"]-1))<3:
                            self.huoli(t)
                        # if self.buffs["归一"]["存在"] and "魂阵" in self.current_buff:
                        #     if self.buffs["鬼遁"]["存在"] is False and t>30:
                        #         self.lin(t)
                        #         self.guixingkaixue(t)
                        #     else:
                        #         self.bing(t)




                        if self.skills["返闭惊魂"]["cold_down"] >5.75:
                            self.sha(t)

                        self.bing(t)
                        self.dou(t)


                        self.lin(t)
                    self.time_pass(t)
                except Exception as e:
                    print(self.skill_sim_log)
                    print(e)
        shangenfg = round(100*self.shanguafugai/total_time,1)

        # # 山卦覆盖率
        # shan_per = 0
        # tp = 0
        # tp_1 = 0
        # for i in self.skill_log:
        #     if "山艮" in i["buff"] and tp_1 == 0:
        #         tp = i["time_stamp"]
        #         tp_1 = 1
        #         print(tp,shan_per)
        #     elif "火离" in i["buff"] and tp_1 == 1:
        #         tp_1 = 0
        #         shan_per += i["time_stamp"]-tp
        #         print(tp,shan_per)
        #     elif "水坎" in i["buff"] and tp_1 == 1:
        #         tp_1 = 0
        #         shan_per += i["time_stamp"]-tp
        #         print(tp,shan_per)



        # 两件套覆盖率测试
        # asd = copy.copy(self.skill_log)
        # bufftime = 0
        # time_sta = []
        # lsst = []
        # for i in asd:
        #     if i["damage"] != 0:
        #         if i["name"] !="灵器":
        #             if i["name"] != "杀星在尾":
        #                 lsst.append(i)
        #
        # for k in lsst:
        #     m = random.random()
        #     if m <0.09:
        #         time_sta.append(k["time_stamp"])
        # # print(time_sta)
        # sta = 0
        # cc = 0
        # for i in time_sta:
        #     if sta>0 and i-sta > 6:
        #         cc+=6
        #         sta = i
        #     elif sta>0 and i-sta<6:
        #         cc += i-sta
        #         sta = i
        #     elif sta == 0:
        #         sta = i
        #
        #
        # print(cc/300000)



        # 添加破招伤害
        po_dou = 0
        po_stamp = 0.0
        po_list = []
        for i in self.skill_log:
            if i["damage"] !="0":
                if i["time_stamp"] - po_stamp >= Skill(self.res).po[6]*5:
                    po_dou += 5
                    po_stamp = i["time_stamp"]
                    if po_dou == 5:
                        po_dou = 0
                        buff = copy.copy(i["buff"])
                        buff_list = []
                        if "荧入白" in buff and self.res["qixue_4"] == "1":
                            buff_list.append("荧入白")
                        if "祝祷" in buff and self.res["qixue_7"] == "1":
                            buff_list.append("祝祷")
                        if "鬼遁" in buff and self.res["qixue_6"] == "1":
                            buff_list.append("鬼遁")
                        damage = Judge(self.res,Skill(self.res).po,buff_list).d()
                        po_list.append(
                            {
                                "name":"破",
                                "damage":int(damage[0]),
                                "buff":buff_list,
                                "time_stamp":i["time_stamp"],
                            }
                        )

        for i in po_list:
            self.skill_log.append(i)
        dam = 0
        dam_dic = {
            "往者定": 0,
            "天斗旋": 0,
            "灵器": 0,
            "破": 0,
            "杀星在尾": 0,
            "兵主逆": 0,
            "三星临": 0,
            "鬼星开穴": 0,
            "火离":0,
            "剑风":0,
            "手附魔": 0,
        }
        dam_num = {
            "往者定": 0,
            "天斗旋": 0,
            "灵器": 0,
            "破": 0,
            "杀星在尾": 0,
            "兵主逆": 0,
            "三星临": 0,
            "鬼星开穴": 0,
            "火离":0,
            "剑风":0,
            "手附魔": 0,
        }
        for i in self.skill_log:
            if i["name"] in dam_dic:
                dam += i["damage"]
                dam_dic[i["name"]] += i["damage"]
                if i["damage"] != 0:
                    dam_num[i["name"]] += 1
        dps = int(dam/total_time)
        damage_ding = str(round(100*dam_dic["往者定"]/dam,2))+"%"
        damage_dou = str(round(100*dam_dic["天斗旋"]/dam,2))+"%"
        damage_ling = str(round(100*dam_dic["灵器"]/dam,2))+"%"
        damage_po = str(round(100*dam_dic["破"]/dam,2))+"%"
        damage_sha = str(round(100*dam_dic["杀星在尾"]/dam,2))+"%"
        damage_bing = str(round(100*dam_dic["兵主逆"]/dam,2))+"%"
        damage_lin = str(round(100*dam_dic["三星临"]/dam,2))+"%"
        damage_kai = str(round(100*dam_dic["鬼星开穴"]/dam,2))+"%"
        damage_huo = str(round(100*dam_dic["火离"]/dam,2))+"%"
        damage_feijian = str(round(100*dam_dic["剑风"]/dam,2))+"%"
        damage_shoufumo = str(round(100 * dam_dic["手附魔"] / dam, 2)) + "%"
        msg = {
                "data": {"dps": dps,
                         "往者定":[damage_ding,dam_num["往者定"]],
                         "天斗旋":[damage_dou,dam_num["天斗旋"]],
                         "灵器":[damage_ling,dam_num["灵器"]],
                         "破":[damage_po,dam_num["破"]],
                         "杀星在尾":[damage_sha,dam_num["杀星在尾"]],
                         "兵主逆":[damage_bing,dam_num["兵主逆"]],
                         "三星临":[damage_lin,dam_num["三星临"]],
                         "鬼星开穴":[damage_kai,dam_num["鬼星开穴"]],
                         "卦象·火离":[damage_huo,dam_num["火离"]],
                         "剑风":[damage_feijian,dam_num["剑风"]],
                         "手附魔": [damage_shoufumo, dam_num["手附魔"]],
                         "skill_log":self.skill_log,
                         "skill_sim_log":self.skill_sim_log,
                         "shangenfg":shangenfg,
                        },
                "code": 20000,
            }
        # print(msg["data"]["手附魔"])
        return msg



def cal(request):
    res = json.loads(request.body)
    msg = Damage(res).start()
    if res["models_check"] == ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
        k_yuanqi = 89
        k_gongji = 214
        k_changshu = 397
        res_yuanqi = copy.copy(res)
        if res["shenyuan_isinclude"] is True and res["qixue_8"] == "1":
            k = 1.1 *k_yuanqi
        else:
            k = 1 *k_yuanqi
        res_yuanqi["yuanqi"] = str ( int(round(int(res_yuanqi["yuanqi"]) + k ,0)))
        res_yuanqi["jichugongji"] = str( int(round((int(res_yuanqi["jichugongji"]) + k *0.18 ),0)))
        res_yuanqi["pofang"] = str (float(res_yuanqi["pofang"]) +100*k *0.3/35737.5)
        res_yuanqi["huixin"] = str (float(res_yuanqi["huixin"]) +100*k *0.47/35737.5)
        res_gongji = copy.copy(res)
        res_gongji["jichugongji"] = str(int(res_gongji["jichugongji"]) + k_gongji )
        res_wushuang = copy.copy(res)
        res_wushuang["wushuang"] = str(float(res_wushuang["wushuang"]) + k_changshu/344.5875 )
        res_pofang = copy.copy(res)
        res_pofang["pofang"] = str (float(res_pofang["pofang"]) + k_changshu/357.375 )
        res_huixin = copy.copy(res)
        res_huixin["huixin"] = str (float(res_huixin["huixin"]) + k_changshu/357.375 )
        res_huixiao = copy.copy(res)
        res_huixiao["huixiao"] = str (float(res_huixiao["huixiao"]) + k_changshu/125.0625 )
        res_pozhao = copy.copy(res)
        res_pozhao["pozhao"] = str (int(res_pozhao["pozhao"]) + k_changshu )
        dps_ori = msg["data"]["dps"]
        dps_yuanqi = Damage(res_yuanqi).start()["data"]["dps"] - dps_ori
        dps_gongji = Damage(res_gongji).start()["data"]["dps"] - dps_ori
        dps_wushuang = Damage(res_wushuang).start()["data"]["dps"] - dps_ori
        dps_pofang = Damage(res_pofang).start()["data"]["dps"] - dps_ori
        dps_huixin = Damage(res_huixin).start()["data"]["dps"] - dps_ori
        dps_huixiao = Damage(res_huixiao).start()["data"]["dps"] - dps_ori
        dps_pozhao = Damage(res_pozhao).start()["data"]["dps"] - dps_ori
        msg["data"]["dps_yuanqi"] = dps_yuanqi
        msg["data"]["dps_gongji"] = dps_gongji
        msg["data"]["dps_wushuang"] = dps_wushuang
        msg["data"]["dps_pofang"] = dps_pofang
        msg["data"]["dps_huixin"] = dps_huixin
        msg["data"]["dps_huixiao"] = dps_huixiao
        msg["data"]["dps_pozhao"] = dps_pozhao

        msg["data"]["dps_yuanqi_per"] = round(100*dps_yuanqi/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
        msg["data"]["dps_gongji_per"] = round(100*dps_gongji/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
        msg["data"]["dps_wushuang_per"] = round(100*dps_wushuang/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
        msg["data"]["dps_pofang_per"] = round(100*dps_pofang/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
        msg["data"]["dps_huixin_per"] = round(100*dps_huixin/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
        msg["data"]["dps_huixiao_per"] = round(100*dps_huixiao/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
        msg["data"]["dps_pozhao_per"] = round(100*dps_pozhao/max([dps_yuanqi,dps_gongji,dps_wushuang,dps_pofang,dps_huixin,dps_huixiao,dps_pozhao]),2)
    # gj = []
    # x = range(0,50)
    # dps_oril = msg["data"]["dps"]
    #
    # for k in range(0,50):
    #     res_gj = copy.copy(res)
    #     res_gj["jichugongji"] = str(int(res_gj["jichugongji"]) + k*175)
    #     dps_gj = Damage(res_gj).start()["data"]["dps"] - dps_oril
    #     gj.append(dps_gj)
    # ws = []
    # for k in range(0,50):
    #     res_ws = copy.copy(res)
    #     res_ws["jichugongji"] = str (float(res_ws["wushuang"]) + 325/344.5875 )
    #     dps_ws = Damage(res_gj).start()["data"]["dps"] - dps_oril
    #     ws.append(dps_ws)
    #
    #
    # pyplot.figure(figsize=(20, 8), dpi=80)
    # pyplot.plot(x, gj, label='攻击', )
    # pyplot.plot(x, ws, label='无双', )
    # pyplot.show()
    # print(gj)
    return JsonResponse(msg, safe=False)

def auth(request):
    res = json.loads(request.body)
    result = [
        ["技能","命中伤害","会心伤害"],
        ["三星临+奇穴秘籍",int(Judge(res,Skill(res).lin,[]).t()[0]),int(Judge(res,Skill(res).lin,[]).t()[1])],
        ["三星临+奇穴秘籍+祝祷",int(Judge(res,Skill(res).lin,["祝祷"]).t()[0]),int(Judge(res,Skill(res).lin,["祝祷"]).t()[1])],
        ["三星临+奇穴秘籍+荧入白",int(Judge(res,Skill(res).lin,["荧入白"]).t()[0]),int(Judge(res,Skill(res).lin,["荧入白"]).t()[1])],
        ["三星临+奇穴秘籍+山艮",int(Judge(res,Skill(res).lin,["山艮"]).t()[0]),int(Judge(res,Skill(res).lin,["山艮"]).t()[1])],
        ["三星临+奇穴秘籍+鬼遁",int(Judge(res,Skill(res).lin,["鬼遁"]).t()[0]),int(Judge(res,Skill(res).lin,["鬼遁"]).t()[1])],
        ["三星临+奇穴秘籍+祝祷山艮",int(Judge(res,Skill(res).lin,["祝祷","山艮"]).t()[0]),int(Judge(res,Skill(res).lin,["祝祷","山艮"]).t()[1])],
        ["三星临+奇穴秘籍+祝祷荧入白",int(Judge(res,Skill(res).lin,["祝祷","荧入白"]).t()[0]),int(Judge(res,Skill(res).lin,["祝祷","荧入白"]).t()[1])],
        ["三星临+奇穴秘籍+祝祷鬼遁",int(Judge(res,Skill(res).lin,["祝祷","鬼遁"]).t()[0]),int(Judge(res,Skill(res).lin,["祝祷","鬼遁"]).t()[1])],
        ["三星临+奇穴秘籍+荧入白山艮",int(Judge(res,Skill(res).lin,["荧入白","山艮"]).t()[0]),int(Judge(res,Skill(res).lin,["荧入白","山艮"]).t()[1])],
        ["三星临+奇穴秘籍+荧入白鬼遁",int(Judge(res,Skill(res).lin,["荧入白","鬼遁"]).t()[0]),int(Judge(res,Skill(res).lin,["荧入白","鬼遁"]).t()[1])],
        ["三星临+奇穴秘籍+山艮鬼遁",int(Judge(res,Skill(res).lin,["山艮","鬼遁"]).t()[0]),int(Judge(res,Skill(res).lin,["山艮","鬼遁"]).t()[1])],
        ["三星临+奇穴秘籍+鬼遁祝祷荧入白",int(Judge(res,Skill(res).lin,["鬼遁","祝祷","荧入白"]).t()[0]),int(Judge(res,Skill(res).lin,["鬼遁","祝祷","荧入白"]).t()[1])],
        ["三星临+奇穴秘籍+山艮祝祷荧入白",int(Judge(res,Skill(res).lin,["山艮","祝祷","荧入白"]).t()[0]),int(Judge(res,Skill(res).lin,["山艮","祝祷","荧入白"]).t()[1])],
        ["三星临+奇穴秘籍+鬼遁山艮祝祷荧入白",int(Judge(res,Skill(res).lin,["鬼遁","山艮","祝祷","荧入白"]).t()[0]),int(Judge(res,Skill(res).lin,["鬼遁","山艮","祝祷","荧入白"]).t()[1])],
        ["兵主逆+奇穴秘籍",int(Judge(res,Skill(res).bing,[]).t()[0]),int(Judge(res,Skill(res).bing,[]).t()[1])],
        ["天斗旋+奇穴秘籍",int(Judge(res,Skill(res).dou,[]).t()[0]),int(Judge(res,Skill(res).dou,[]).t()[1])],
        ["往者定",int(Judge(res,Skill(res).ding,[]).t()[0]),int(Judge(res,Skill(res).ding,[]).t()[1])],
        ["灵器",int(Judge(res,Skill(res).ling,[]).t()[0]),int(Judge(res,Skill(res).ling,[]).t()[1])],
        ["破",int(Judge(res,Skill(res).po,[]).t()[0]),int(Judge(res,Skill(res).po,[]).t()[1])],
        ["杀星在尾",int(Judge(res,Skill(res).sha,[]).t()[0]),int(Judge(res,Skill(res).sha,[]).t()[1])],
        ["鬼星开穴+奇穴秘籍",int(Judge(res,Skill(res).kai,[]).t()[0]),int(Judge(res,Skill(res).kai,[]).t()[1])],
        ["卦象·火离",int(Judge(res,Skill(res).huo,[]).t()[0]),int(Judge(res,Skill(res).huo,[]).t()[1])],
    ]
    msg = {
                "data": result,
                "code": 20000,
            }
    return JsonResponse(msg, safe=False)


def cal_dan(request):
    res = json.loads(request.body)
    res['models_check'] = ['稳定模式(欧皇起卦） -- 并提供当前属性收益']
    if res["shenyuan_isinclude"] is True and res["qixue_8"] == "1":
        k = 1.1
    else:
        k = 1
    result = Damage(res).start()
    if res["huanzhuang"]["before"]["jinglian"] == "精炼0":
        jinglian_before  = 1
    elif res["huanzhuang"]["before"]["jinglian"] == "精炼1":
        jinglian_before = 1.005
    elif res["huanzhuang"]["before"]["jinglian"] == "精炼2":
        jinglian_before = 1.0125
    elif res["huanzhuang"]["before"]["jinglian"] == "精炼3":
        jinglian_before = 1.02375
    elif res["huanzhuang"]["before"]["jinglian"] == "精炼4":
        jinglian_before = 1.038
    elif res["huanzhuang"]["before"]["jinglian"] == "精炼5":
        jinglian_before = 1.055
    elif res["huanzhuang"]["before"]["jinglian"] == "精炼6":
        jinglian_before = 1.075
    yuanqi_before = round(int(res["huanzhuang"]["before"]["yuanqi"])*jinglian_before,0)
    gongji_before = round(int(res["huanzhuang"]["before"]["gongji"])*jinglian_before,0)
    huixin_before = round(int(res["huanzhuang"]["before"]["huixin"])*jinglian_before,0)
    huixiao_before = round(int(res["huanzhuang"]["before"]["huixiao"])*jinglian_before,0)
    pofang_before = round(int(res["huanzhuang"]["before"]["pofang"])*jinglian_before,0)
    wushuang_before = round(int(res["huanzhuang"]["before"]["wushuang"])*jinglian_before,0)
    pozhao_before = round(int(res["huanzhuang"]["before"]["pozhao"])*jinglian_before,0)
    if "yuanqi" in res["huanzhuang"]["before"]["kong"]:
        yuanqi_before += 16
    if "gongji" in res["huanzhuang"]["before"]["kong"]:
        gongji_before += 38
    if "huixin" in res["huanzhuang"]["before"]["kong"]:
        huixin_before += 72
    if "huixiao" in res["huanzhuang"]["before"]["kong"]:
        huixiao_before += 72
    if "pofang" in res["huanzhuang"]["before"]["kong"]:
        pofang_before += 72
    if "wushuang" in res["huanzhuang"]["before"]["kong"]:
        wushuang_before += 72
    if "pozhao" in res["huanzhuang"]["before"]["kong"]:
        pozhao_before += 72
    if res["huanzhuang"]["after"]["jinglian"] == "精炼0":
        jinglian_after  = 1
    elif res["huanzhuang"]["after"]["jinglian"] == "精炼1":
        jinglian_after = 1.005
    elif res["huanzhuang"]["after"]["jinglian"] == "精炼2":
        jinglian_after = 1.0125
    elif res["huanzhuang"]["after"]["jinglian"] == "精炼3":
        jinglian_after = 1.02375
    elif res["huanzhuang"]["after"]["jinglian"] == "精炼4":
        jinglian_after = 1.0375
    elif res["huanzhuang"]["after"]["jinglian"] == "精炼5":
        jinglian_after = 1.055
    elif res["huanzhuang"]["after"]["jinglian"] == "精炼6":
        jinglian_after = 1.075
    yuanqi_after = round(int(res["huanzhuang"]["after"]["yuanqi"])*jinglian_after,0)
    gongji_after = round(int(res["huanzhuang"]["after"]["gongji"])*jinglian_after,0)
    huixin_after = round(int(res["huanzhuang"]["after"]["huixin"])*jinglian_after,0)
    huixiao_after = round(int(res["huanzhuang"]["after"]["huixiao"])*jinglian_after,0)
    pofang_after = round(int(res["huanzhuang"]["after"]["pofang"])*jinglian_after,0)
    wushuang_after = round(int(res["huanzhuang"]["after"]["wushuang"])*jinglian_after,0)
    pozhao_after = round(int(res["huanzhuang"]["after"]["pozhao"])*jinglian_after,0)
    if "yuanqi" in res["huanzhuang"]["after"]["kong"]:
        yuanqi_after += 16
    if "gongji" in res["huanzhuang"]["after"]["kong"]:
        gongji_after += 38
    if "huixin" in res["huanzhuang"]["after"]["kong"]:
        huixin_after += 72
    if "huixiao" in res["huanzhuang"]["after"]["kong"]:
        huixiao_after += 72
    if "pofang" in res["huanzhuang"]["after"]["kong"]:
        pofang_after += 72
    if "wushuang" in res["huanzhuang"]["after"]["kong"]:
        wushuang_after += 72
    if "pozhao" in res["huanzhuang"]["after"]["kong"]:
        pozhao_after += 72
    new_res = copy.copy(res)
    new_res["yuanqi"] = str(int(int(new_res["yuanqi"])+(yuanqi_after-yuanqi_before)*k))
    new_res["jichugongji"] = str(int(int(new_res["jichugongji"])+gongji_after-gongji_before+ (yuanqi_after-yuanqi_before)*k*0.18))
    new_res["huixin"] = str(float(new_res["huixin"])+(huixin_after-huixin_before)/357.375+(yuanqi_after-yuanqi_before)*100*k *0.47/35737.5)
    new_res["huixiao"] = str(float(new_res["huixiao"])+(huixiao_after-huixiao_before)/125.0625)
    new_res["pofang"] = str(float(new_res["pofang"])+(pofang_after-pofang_before)/357.375+(yuanqi_after-yuanqi_before)*100*k *0.3/35737.5)
    new_res["wushuang"] = str(float(new_res["wushuang"])+ (wushuang_after-wushuang_before)/344.5875)
    new_res["pozhao"] = str(float(new_res["pozhao"])   +(pozhao_after-pozhao_before))
    new_result = Damage(new_res).start()
    ms = {
        'dps':result["data"]["dps"],
        'new_dps':new_result["data"]["dps"]
    }
    msg = {
                "data": ms,
                "code": 20000,
            }
    return JsonResponse(msg, safe=False)


#下载茗伊BUFF监控
import os
path = os.path.dirname(__file__)
def buff_download(request):
    file = open(path+'/buff.jx3dat','rb')
    response = HttpResponse(content_type='application/octet-stream')
    response['Content-Disposition'] = "attachment;filename= buff.jx3dat"
    response = FileResponse(file)
    return response


import pymysql
from backend.db_set import db
db_data = db


def db_login():
    try:
        db = pymysql.connect(db_data['server'], db_data['user_name'], db_data['pwd'], "yantian", charset='utf8')
    except Exception as e:
        os.system('reboot')
    return db

def check_zhuangbei(request):
    res = json.loads(request.body)
    # print(res)
    db = db_login()
    cursor = db.cursor()
    sql = "select id,name,position,level,beizhu from jx3_equipment where position = '{0}' and level>=3800 ".format(res['positon'])
    wuhuang_sql =  " and name not like '无皇%'"
    if res["wuhuang"] is False:
        sql += wuhuang_sql + ' ORDER BY level desc'
    else:
        sql += ' ORDER BY level desc'
    cursor.execute(sql)
    resu = cursor.fetchall()
    cursor.close()
    db.close()
    # print(res)
    msg = {
        "data": resu,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


def zhuangbei_detail(request):
    res = json.loads(request.body)
    # print(res)
    db = db_login()
    cursor = db.cursor()
    sql = "select * from jx3_equipment where id = '{0}'".format(res['value'])
    cursor.execute(sql)
    resu = cursor.fetchone()
    cursor.close()
    db.close()
    msg = {
        "data": resu,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


def store_zhuangbei_fangan(request):
    res = json.loads(request.body)
    db = db_login()
    cursor = db.cursor()
    sql = 'insert into jx3_equipment_fangan(uuid,content) VALUES ("{0}","{1}")'.format(res["uuid"],res)
    # print(sql)
    cursor.execute(sql)
    db.commit()
    cursor.close()
    db.close()
    msg = {
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


def read_zhuangbei_fangan(request):
    res = json.loads(request.body)
    # print(res['uuid'])
    db = db_login()
    cursor = db.cursor()
    sql = "select content from jx3_equipment_fangan where uuid = '{0}'".format(res['uuid'])
    cursor.execute(sql)
    resu = eval(cursor.fetchone()[0])
    # print(type(resu),resu)
    cursor.close()
    db.close()
    msg = {
        "data": resu,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)